
extends Area2D

var player_in_range:bool=false


@onready var sprite = $"../AnimatedSprite2D"


func _ready() -> void:
	sprite.play("broken")

func _process(delta: float) -> void:
	if GameUtiles.l5_repaired:
		sprite.play("repaired")
	if GameUtiles.fly:
		get_tree().change_scene_to_file("res://scenes/level_6.tscn")


func _on_body_entered(body) -> void:
	if body.name =="player":
		player_in_range=true

func _on_body_exited(body) -> void:
	if body.name =="player":
		player_in_range=false
		
func _input(event):
	if event.is_action_pressed("pick_up") and player_in_range and GameUtiles.move_allow:
		if not GameUtiles.l5_repaired:
			if GameUtiles.player_bag.get("iron",0) >0 or GameUtiles.ingredients.has("iron"):
				DialogueManager.show_dialogue_balloon(load("res://dialogues/items/pao.dialogue"),"iron")
			elif GameUtiles.player_bag.get("steel",0) >0 or GameUtiles.ingredients.has("steel"):
				DialogueManager.show_dialogue_balloon(load("res://dialogues/items/pao.dialogue"),"steel")
			else:
				DialogueManager.show_dialogue_balloon(load("res://dialogues/items/pao.dialogue"),"pao")
		elif GameUtiles.l5_repaired:
			if not GameUtiles.l5_rope:
				if GameUtiles.player_bag.get("rope",0) >0 or GameUtiles.ingredients.has("rope"):
					DialogueManager.show_dialogue_balloon(load("res://dialogues/items/pao.dialogue"),"rope")
				else:
					DialogueManager.show_dialogue_balloon(load("res://dialogues/items/pao.dialogue"),"no_rope")
			if GameUtiles.l5_rope:
				if not GameUtiles.l5_powered:
					if GameUtiles.player_bag.get("strong_power",0) >0 or GameUtiles.ingredients.has("strong_power"):
						DialogueManager.show_dialogue_balloon(load("res://dialogues/items/pao.dialogue"),"power")
					else:
						DialogueManager.show_dialogue_balloon(load("res://dialogues/items/pao.dialogue"),"no_power")
